<!-- 
此组件初始化时不会自动加载数据，请在mounted中 this.$refs.[].initData()
如果放在dialog里面的吗，请在dialog的open事件中用this.$nextTick进行加载
 -->
<template>
  <div>
    <list id-key="id" ref="list" unit="发票" :disabled="disabled" :show-query="showQuery" show-checkbox
      :query-params="queryParams" :expand-query="expandQuery" page @get-data="onGetData" custom-get-data :data="data"
      :total="total">
      <template #toolbar-left>
        <slot name="toolbar-left"></slot>
      </template>
      <template #query>
        <!-- <el-form-item label="ID">
          <el-input v-model.trim="queryParams.id" clearable></el-input>
        </el-form-item> -->
        <div>
          <el-form-item label="发票号码">
            <el-input v-model.trim="queryParams.invoiceNo" placeholder="发票号码" clearable></el-input>
          </el-form-item>
          <el-form-item label="发票代码">
            <el-input v-model.trim="queryParams.invoiceCode" placeholder="发票代码" clearable></el-input>
          </el-form-item>
          <el-form-item label="流水号">
            <el-input v-model.trim="queryParams.serialNo" placeholder="流水号" clearable></el-input>
          </el-form-item>
          <el-form-item label="发票状态">
            <el-select v-model="queryParams.statuses" clearable multiple collapse-tags>
              <el-option label="新增蓝票" :value="1"></el-option>
              <el-option label="冲红红票" :value="3"></el-option>
              <el-option label="作废票" :value="2"></el-option>
              <el-option label="开票失败" :value="6"></el-option>
            </el-select>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="购方抬头">
            <el-input v-model.trim="queryParams.buyerTitleName" clearable></el-input>
          </el-form-item>
          <el-form-item label="销方抬头">
            <el-input v-model.trim="queryParams.sellerTitleName" clearable></el-input>
          </el-form-item>
        </div>
      </template>
      <template #column>
        <el-table-column prop="status" width="90" label="发票状态" align="center">
          <template #default="{ row }">
            <el-tooltip :content="row.nuoNuoMessage" :disabled="row.status != 6">
              <el-tag :type="getStatusType(row.status)">{{
                  row.statusText
              }}</el-tag>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column prop="invoiceNo" width="90" label="发票号码">
          <template #default="{ row }">
            <span class="c-link" @click="openDetail(row.id)">{{ row.invoiceNo || "无" }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="invoiceCode" width="110" label="发票代码" />
        <el-table-column prop="serialNo" width="130" label="开票流水号" show-overflow-tooltip />
        <el-table-column prop="invoiceAmount" width="100" label="开票金额" align="right">
          <template #default="{ row }"> ￥{{ row.invoiceAmount }} </template>
        </el-table-column>
        <el-table-column prop="nuoNuoStatusText" width="180" label="诺诺开票结果" show-overflow-tooltip>
          <template #default="{ row }">
            <el-tag v-show="!row.nuoNuoSyncFinished">同步中</el-tag>{{ row.nuoNuoStatusText }}
          </template>
        </el-table-column>
        <el-table-column prop="buyerTitleName" width="180" label="购方抬头" show-overflow-tooltip />
        <el-table-column prop="sellerTitleName" width="180" label="销方抬头" show-overflow-tooltip />
        <el-table-column prop="remark" min-width="100" label="备注" show-overflow-tooltip />
        <el-table-column prop="creatorUserName" width="80" label="创建人" show-overflow-tooltip />
        <el-table-column prop="creationTime" width="120" label="创建时间" sortable="custom">
          <template v-slot="{ row }">
            <span>{{ row.creationTime | toShortDatetimeString }}</span>
          </template>
        </el-table-column>
        <!-- slot[column] -->
        <slot name="column"></slot>
        <!--/ slot[column]-->
      </template>
    </list>
    <detail-dialog ref="detailDialog" />
  </div>
</template>
<script>
import listMixin from "@/mixins/list";
import list from "@/components/common/list";
import detailDialog from "./detailDialog";
import api from "@/api/fam/invoice";
export default {
  mixins: [listMixin],
  components: {
    list,
    detailDialog
  },
  props: {},
  data() {
    return {
      data: [],
      total: 0,
      //查询条件字段
      queryParams: {
        invoiceNo: "",
        invoiceCode: "",
        serialNo: "",
        buyerTitleName: "",
        sellerTitleName: "",
        statuses: [],
      }
    };
  },
  methods: {
    async onGetData(params) {
      this.$refs.list.loading();
      let res = await api.getPageList(params);
      this.$refs.list.loading(false);
      if (res.code != 0) {
        return;
      }
      this.data = res.data.list;
      this.total = res.data.total;
    },
    getStatusType(status) {
      var text = "";
      switch (status) {
        case 0:
          text = "info";
          break;
        case 1:
          text = "";
          break;
        case 2:
          //作废
          text = "info";
          break;
        case 3:
          //冲红
          text = "warning";
          break;
        case 6:
          text = "danger";
          break;
      }
      return text;
    },
    openInvoice(url) {
      window.open(url);
    },
    openDetail(id) {
      this.$refs.detailDialog.openDetail(id);
    }
  },
};
</script>